package org.xdq.yzmdemo;

import jakarta.servlet.*;
import jakarta.servlet.http.*;
import jakarta.servlet.annotation.*;

import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.io.OutputStream;

@WebServlet("/yzm")
public class YzmServlet extends HttpServlet {


    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        VerificationCode code = new VerificationCode();
        BufferedImage image = code.getImage();
        String textCode = code.getText();

        String key = request.getParameter("key");

        YzmCache.add(key,textCode);

        OutputStream out = response.getOutputStream();
        ImageIO.write(image,"jpeg",out);

        out.flush();
        out.close();



    }


}
